<?php
include 'include/setup.php';

$username = $_POST['username'];
$password = $_POST['password'];

$username = addslashes($username);
$password = addslashes($password);

$set = new setup();

if(!isset($_POST['username'])&&!isset($_POST['password'])) //Έλεγχος αν υπάρχει username και password (αν δεν υπάρχει εμφανίζει την σελίδα)
{?>

<head>
    <link href="css/admin_style.css" rel="stylesheet" type="text/css" />
</head>

<body id=login_body>
<div id="login_box">
    <div id="loginHeader">
        <img src="imgs/logo.png" width="100%" alt="newcareer">
    </div>
    <div id="login_info">
        <?php
        if(mysqli_connect_error())
        {
            echo 'Cannot connect to database.';
            exit;
        }
        ?>
        <p style="text-align: center; font-family: calibri">Enter user name and password</p>
    </div>
    <hr style="color: white;">
    <form id="login_form" name="form_login" method="post" action="index.php">
        <div class="login_input_div">
            <img src="imgs/user_icon.png" alt="Username" class="login_img">
            <input id="username_input" class="login_input" type="text" title="Username" name="username">
        </div>
        <div class="login_input_div">
            <img src="imgs/password_icon.png" alt="Password" class="login_img">
            <input id="password_input" class="login_input" type="password" title="Password" name="password">
        </div>
        <input id="login_button" type="submit" value="Login">
    </form>
</div>
<?php
}
else
{
    $login = $set->login('users', $username, $password);//επιστρέφει true αν υπάρχει χρήστης

    if($login)
    {
        $set->redirect("http://192.185.116.17/~wwwmsc/administrator/home.php");
    }
    else
    {
        echo '<h1>Login Fail</br>try again</h1>';
    }
}
?>